package com.group2.edu.realtime.dws.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 高耀
 * @date 2024/12/16 10:15<p></p>
 *
 * 此工具类提供方法使用IK进行分词操作
 */
public class KeywordUtil {
    public static List<String> splitWords(String text) {
        List<String> keywordList = new ArrayList<>();
        StringReader reader = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(reader, true);
        try {
            Lexeme lexeme = null;
            while ((lexeme = ik.next()) != null) {
                String keyword = lexeme.getLexemeText();
                keywordList.add(keyword);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return keywordList;
    }

    public static void main(String[] args) {
        List<String> list = splitWords("数据库hadoopflinkjavapython多线程大数据");
        System.out.println(list);
    }
}
